package cn.stylefeng.guns.modular.business.frequency.announcement.controller;

import cn.stylefeng.guns.core.annotion.BusinessLog;
import cn.stylefeng.guns.core.enums.LogAnnotionOpTypeEnum;
import cn.stylefeng.guns.core.pojo.response.ResponseData;
import cn.stylefeng.guns.core.pojo.response.SuccessResponseData;
import cn.stylefeng.guns.modular.business.custom.annotations.RepeatSubmit;
import cn.stylefeng.guns.modular.business.frequency.announcement.model.param.AnnouncementParam;
import cn.stylefeng.guns.modular.business.frequency.announcement.service.AnnouncementService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 公告 控制器
 *
 * @author: 余杰
 * @date: 2022/11/14 13:38
 */
@RestController
public class AnnouncementController {

    @Resource
    private AnnouncementService announcementService;

    /**
     * 分页查询公告
     *
     * @author 余杰
     * @date 2022/11/14 13:38
     */
    @GetMapping("/announcement/page")
    @BusinessLog(title = "公告_分页查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData page(AnnouncementParam announcementParam) {
        return new SuccessResponseData(announcementService.page(announcementParam));
    }

    /**
     * 获取全部公告
     *
     * @author 余杰
     * @date 2022/11/14 13:38
     */
    @GetMapping("/announcement/list")
    @BusinessLog(title = "公告_查询所有", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData list(AnnouncementParam announcementParam) {
        return new SuccessResponseData(announcementService.list(announcementParam));
    }

    /**
     * 查看详情公告
     *
     * @author 余杰
     * @date 2022/11/14 13:38
     */
    @GetMapping("/announcement/detail")
    @BusinessLog(title = "公告_查看详情", opType = LogAnnotionOpTypeEnum.DETAIL)
    public ResponseData detail( AnnouncementParam announcementParam) {
        return new SuccessResponseData(announcementService.detail(announcementParam));
    }

    /**
     * 添加公告
     *
     * @author 余杰
     * @date 2022/11/14 13:38
     */
    @PostMapping("/announcement/add")
    @BusinessLog(title = "公告_增加", opType = LogAnnotionOpTypeEnum.ADD)
    @RepeatSubmit(expireSeconds = 3)
    public ResponseData add(@RequestBody  AnnouncementParam announcementParam) {
        announcementService.add(announcementParam);
        return new SuccessResponseData();
    }

    /**
     * 删除公告
     *
     * @author 余杰
     * @date 2022/11/14 13:38
     */
    @PostMapping("/announcement/delete")
    @BusinessLog(title = "公告_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public ResponseData delete(@RequestBody  AnnouncementParam announcementParam) {
        announcementService.delete(announcementParam);
        return new SuccessResponseData();
    }

    /**
     * 编辑公告
     *
     * @author 余杰
     * @date 2022/11/14 13:38
     */
    @PostMapping("/announcement/edit")
    @BusinessLog(title = "公告_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    public ResponseData edit(@RequestBody AnnouncementParam announcementParam) {
        announcementService.edit(announcementParam);
        return new SuccessResponseData();
    }


}
